<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">




<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
  </script>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />



  <link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico?v=5.1.4">







  <meta name="keywords" content="iOS," />





  <link rel="alternate" href="/atom.xml" title="Swift社区" type="application/atom+xml" />






<meta name="description" content="一：简介最近项目在做了身份证银行卡识别之后，开始实现人脸识别和活体识别，其中人脸识别包括人脸入库、人脸查找、人脸1：N对比、人脸N:N对比，另外活体识别运用在安全登录功能。 大家都熟知的支付宝使用face++ 的服务来实现人脸识别，在实际项目中使用了讯飞的人脸识别SDK进行二次封装来实现活体识别。主要实现了张嘴和摇头两个活体动作的识别。据我所知，讯飞的服务是基于face++,识别率还是很高，并且i">
<meta name="keywords" content="iOS">
<meta property="og:type" content="article">
<meta property="og:title" content="人脸识别 -- 活体检测(张嘴摇头识别)">
<meta property="og:url" content="https://fanbaoying.github.io/人脸识别-活体检测-张嘴摇头识别/index.html">
<meta property="og:site_name" content="Swift社区">
<meta property="og:description" content="一：简介最近项目在做了身份证银行卡识别之后，开始实现人脸识别和活体识别，其中人脸识别包括人脸入库、人脸查找、人脸1：N对比、人脸N:N对比，另外活体识别运用在安全登录功能。 大家都熟知的支付宝使用face++ 的服务来实现人脸识别，在实际项目中使用了讯飞的人脸识别SDK进行二次封装来实现活体识别。主要实现了张嘴和摇头两个活体动作的识别。据我所知，讯飞的服务是基于face++,识别率还是很高，并且i">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/2829694-b10687203a879c89.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/2829694-93809e5d166a1633.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/2829694-3414999985ccd080.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/2829694-19d0d89539d05cbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2829694-48307b4d71bc5800.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300">
<meta property="og:updated_time" content="2018-03-19T01:22:06.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="人脸识别 -- 活体检测(张嘴摇头识别)">
<meta name="twitter:description" content="一：简介最近项目在做了身份证银行卡识别之后，开始实现人脸识别和活体识别，其中人脸识别包括人脸入库、人脸查找、人脸1：N对比、人脸N:N对比，另外活体识别运用在安全登录功能。 大家都熟知的支付宝使用face++ 的服务来实现人脸识别，在实际项目中使用了讯飞的人脸识别SDK进行二次封装来实现活体识别。主要实现了张嘴和摇头两个活体动作的识别。据我所知，讯飞的服务是基于face++,识别率还是很高，并且i">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/2829694-b10687203a879c89.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://fanbaoying.github.io/人脸识别-活体检测-张嘴摇头识别/"/>





  <title>人脸识别 -- 活体检测(张嘴摇头识别) | Swift社区</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    
    <a href="https://github.com/SwiftCommunityRes" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Swift社区</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">做最好的 Swift 社区</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://fanbaoying.github.io/人脸识别-活体检测-张嘴摇头识别/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Swift社区">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars.githubusercontent.com/u/84354365?v=4">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Swift社区">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">人脸识别 -- 活体检测(张嘴摇头识别)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-03-19T09:14:22+08:00">
                2018-03-19
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/iOS-识别集/" itemprop="url" rel="index">
                    <span itemprop="name">iOS 识别集</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>

                <!-- 
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                -->
                <span title="字数统计">
                  数字统计 1,773字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>

                <!-- 
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                --> 

                <span title="阅读时长">
                  阅读时长 8分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一：简介"><a href="#一：简介" class="headerlink" title="一：简介"></a>一：简介</h2><p>最近项目在做了身份证银行卡识别之后，开始实现人脸识别和活体识别，其中人脸识别包括人脸入库、人脸查找、人脸1：N对比、人脸N:N对比，另外活体识别运用在安全登录功能。</p>
<p>大家都熟知的支付宝使用face++ 的服务来实现人脸识别，在实际项目中使用了讯飞的人脸识别SDK进行二次封装来实现活体识别。主要实现了张嘴和摇头两个活体动作的识别。据我所知，讯飞的服务是基于face++,识别率还是很高，并且iOS和Android都对应有封装好的SDK。</p>
<p>在实际运用中，有很多app为了高度保证用户使用的安全问题，除了常规的账号密码登录之外，相继实现了指纹登录，手势登录，第三方登陆（QQ、微信、支付宝）、刷脸登录，接下里我就和大家分享一下如何实现人脸识别的活体检测，这是实现刷脸登录最基础的实现。</p>
<p>另外，这些博文都是来源于我日常开发中的技术总结，在时间允许的情况下，我会针对技术点分别分享iOS、Android两个版本，尽量附上demo以供大家参考，如果有其他技术点需要，可在文章后留言，我会尽全力帮助大家。</p>
<a id="more"></a>
<h2 id="二：实现思路分析"><a href="#二：实现思路分析" class="headerlink" title="二：实现思路分析"></a>二：实现思路分析</h2><ol>
<li><p>点击识别按钮，调用相机</p>
</li>
<li><p>CameraRules类，检测相机权限</p>
</li>
<li><p>初始化页面，创建摄像页面，创建张嘴数据和摇头数据</p>
</li>
<li><p>开启识别，脸部框识别</p>
</li>
<li><p>脸部部位识别，脸部识别判断是否检测到人脸</p>
</li>
<li><p>检测到人脸之后，判断位置</p>
</li>
<li><p>位置判断合适，判断是否张嘴</p>
</li>
<li><p>张嘴判断完毕，验证是否摇头</p>
</li>
<li><p>摇头判断完毕，3秒倒计时拍照</p>
</li>
<li><p>拍照完毕，选择重拍或者上传图片</p>
</li>
<li><p>选择重拍重复5-9步骤，选择上传将图片数据回调</p>
</li>
<li><p>数据clean</p>
</li>
</ol>
<h2 id="三：实现源码分析"><a href="#三：实现源码分析" class="headerlink" title="三：实现源码分析"></a>三：实现源码分析</h2><p>根据实现思路分析，一步步进行编码实现：</p>
<h4 id="1-点击识别按钮，调用相机"><a href="#1-点击识别按钮，调用相机" class="headerlink" title="1. 点击识别按钮，调用相机"></a>1. 点击识别按钮，调用相机</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">if([CameraRules isCapturePermissionGranted])&#123;</span><br><span class="line">        [self setDeviceAuthorized:YES];</span><br><span class="line">    &#125;</span><br><span class="line">    else&#123;</span><br><span class="line">        dispatch_async(dispatch_get_main_queue(), ^&#123;</span><br><span class="line">            NSString* info=@&quot;没有相机权限&quot;;</span><br><span class="line">            [self showAlert:info];</span><br><span class="line">            [self setDeviceAuthorized:NO];</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h4 id="2-CameraRules类，检测相机权限"><a href="#2-CameraRules类，检测相机权限" class="headerlink" title="2. CameraRules类，检测相机权限"></a>2. CameraRules类，检测相机权限</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">//检测相机权限</span><br><span class="line">+(BOOL)isCapturePermissionGranted&#123;</span><br><span class="line">    if([AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)])&#123;</span><br><span class="line">        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];</span><br><span class="line">        if(authStatus ==AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)&#123;</span><br><span class="line">            return NO;</span><br><span class="line">        &#125;</span><br><span class="line">        else if(authStatus==AVAuthorizationStatusNotDetermined)&#123;</span><br><span class="line">            dispatch_semaphore_t sema = dispatch_semaphore_create(0);</span><br><span class="line">            __block BOOL isGranted=YES;</span><br><span class="line">            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) &#123;</span><br><span class="line">                isGranted=granted;</span><br><span class="line">                dispatch_semaphore_signal(sema);</span><br><span class="line">            &#125;];</span><br><span class="line">            dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);</span><br><span class="line">            return isGranted;</span><br><span class="line">        &#125;</span><br><span class="line">        else&#123;</span><br><span class="line">            return YES;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    else&#123;</span><br><span class="line">        return YES;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="3-初始化页面，创建摄像页面，创建张嘴数据和摇头数据"><a href="#3-初始化页面，创建摄像页面，创建张嘴数据和摇头数据" class="headerlink" title="3. 初始化页面，创建摄像页面，创建张嘴数据和摇头数据"></a>3. 初始化页面，创建摄像页面，创建张嘴数据和摇头数据</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">//创建摄像页面，创建张嘴数据和摇头数据</span><br><span class="line">[self faceUI];</span><br><span class="line">[self faceCamera];</span><br><span class="line">[self faceNumber];</span><br></pre></td></tr></table></figure>
<h4 id="4-开启识别，脸部框识别"><a href="#4-开启识别，脸部框识别" class="headerlink" title="4. 开启识别，脸部框识别"></a>4. 开启识别，脸部框识别</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">float cx = (left+right)/2;</span><br><span class="line">float cy = (top + bottom)/2;</span><br><span class="line">float w = right - left;</span><br><span class="line">float h = bottom - top;</span><br><span class="line">float ncx = cy ;</span><br><span class="line">float ncy = cx ;</span><br><span class="line"></span><br><span class="line">CGRect rectFace = CGRectMake(ncx-w/2 ,ncy-w/2 , w, h);</span><br><span class="line"></span><br><span class="line">if(!isFrontCamera)&#123;</span><br><span class="line">    rectFace=rSwap(rectFace);</span><br><span class="line">    rectFace=rRotate90(rectFace, faceImg.height, faceImg.width);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">BOOL isNotLocation = [self identifyYourFaceLeft:left right:right top:top bottom:bottom];</span><br><span class="line"></span><br><span class="line">if (isNotLocation==YES) &#123;</span><br><span class="line">    return nil;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="5-脸部部位识别，脸部识别判断是否检测到人脸"><a href="#5-脸部部位识别，脸部识别判断是否检测到人脸" class="headerlink" title="5. 脸部部位识别，脸部识别判断是否检测到人脸"></a>5. 脸部部位识别，脸部识别判断是否检测到人脸</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">for(id key in keys)&#123;</span><br><span class="line">    id attr=[landmarkDic objectForKey:key];</span><br><span class="line">    if(attr &amp;&amp; [attr isKindOfClass:[NSDictionary class]])&#123;</span><br><span class="line"></span><br><span class="line">        if(!isFrontCamera)&#123;</span><br><span class="line">            p=pSwap(p);</span><br><span class="line">            p=pRotate90(p, faceImg.height, faceImg.width);</span><br><span class="line">        &#125;</span><br><span class="line">        if (isCrossBorder == YES) &#123;</span><br><span class="line">            [self delateNumber];</span><br><span class="line">            return nil;</span><br><span class="line">        &#125;</span><br><span class="line">        p=pScale(p, widthScaleBy, heightScaleBy);</span><br><span class="line"></span><br><span class="line">        [arrStrPoints addObject:NSStringFromCGPoint(p)];</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="6-检测到人脸之后，判断位置动作提醒"><a href="#6-检测到人脸之后，判断位置动作提醒" class="headerlink" title="6. 检测到人脸之后，判断位置动作提醒"></a>6. 检测到人脸之后，判断位置动作提醒</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">if (right - left &lt; 230 || bottom - top &lt; 250) &#123;</span><br><span class="line">    self.textLabel.text = @&quot;太远了&quot;;</span><br><span class="line">    [self delateNumber];</span><br><span class="line">    isCrossBorder = YES;</span><br><span class="line">    return YES;</span><br><span class="line">&#125;else if (right - left &gt; 320 || bottom - top &gt; 320) &#123;</span><br><span class="line">    self.textLabel.text = @&quot;太近了&quot;;</span><br><span class="line">    [self delateNumber];</span><br><span class="line">    isCrossBorder = YES;</span><br><span class="line">    return YES;</span><br><span class="line">&#125;else&#123;</span><br><span class="line">    if (isJudgeMouth != YES) &#123;</span><br><span class="line">        self.textLabel.text = @&quot;请重复张嘴动作&quot;;</span><br><span class="line">        [self tomAnimationWithName:@&quot;openMouth&quot; count:2];</span><br><span class="line"></span><br><span class="line">        if (left &lt; 100 || top &lt; 100 || right &gt; 460 || bottom &gt; 400) &#123;</span><br><span class="line">            isCrossBorder = YES;</span><br><span class="line">            isJudgeMouth = NO;</span><br><span class="line">            self.textLabel.text = @&quot;调整下位置先&quot;;</span><br><span class="line">            [self delateNumber];</span><br><span class="line">            return YES;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;else if (isJudgeMouth == YES &amp;&amp; isShakeHead != YES) &#123;</span><br><span class="line">        self.textLabel.text = @&quot;请重复摇头动作&quot;;</span><br><span class="line">        [self tomAnimationWithName:@&quot;shakeHead&quot; count:4];</span><br><span class="line">        number = 0;</span><br><span class="line">    &#125;else&#123;</span><br><span class="line">        takePhotoNumber += 1;</span><br><span class="line">        if (takePhotoNumber == 2) &#123;</span><br><span class="line">            [self timeBegin];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    isCrossBorder = NO;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="7-位置判断合适，判断是否张嘴"><a href="#7-位置判断合适，判断是否张嘴" class="headerlink" title="7. 位置判断合适，判断是否张嘴"></a>7. 位置判断合适，判断是否张嘴</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">if (rightX &amp;&amp; leftX &amp;&amp; upperY &amp;&amp; lowerY &amp;&amp; isJudgeMouth != YES) &#123;</span><br><span class="line"></span><br><span class="line">    number ++;</span><br><span class="line">    if (number == 1 || number == 300 || number == 600 || number ==900) &#123;</span><br><span class="line">        mouthWidthF = rightX - leftX &lt; 0 ? abs(rightX - leftX) : rightX - leftX;</span><br><span class="line">        mouthHeightF = lowerY - upperY &lt; 0 ? abs(lowerY - upperY) : lowerY - upperY;</span><br><span class="line">        NSLog(@&quot;%d,%d&quot;,mouthWidthF,mouthHeightF);</span><br><span class="line">    &#125;else if (number &gt; 1200) &#123;</span><br><span class="line">        [self delateNumber];</span><br><span class="line">        [self tomAnimationWithName:@&quot;openMouth&quot; count:2];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    mouthWidth = rightX - leftX &lt; 0 ? abs(rightX - leftX) : rightX - leftX;</span><br><span class="line">    mouthHeight = lowerY - upperY &lt; 0 ? abs(lowerY - upperY) : lowerY - upperY;</span><br><span class="line">    NSLog(@&quot;%d,%d&quot;,mouthWidth,mouthHeight);</span><br><span class="line">    NSLog(@&quot;张嘴前：width=%d，height=%d&quot;,mouthWidthF - mouthWidth,mouthHeight - mouthHeightF);</span><br><span class="line">    if (mouthWidth &amp;&amp; mouthWidthF) &#123;</span><br><span class="line"></span><br><span class="line">        if (mouthHeight - mouthHeightF &gt;= 20 &amp;&amp; mouthWidthF - mouthWidth &gt;= 15) &#123;</span><br><span class="line">            isJudgeMouth = YES;</span><br><span class="line">            imgView.animationImages = nil;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="8-张嘴判断完毕，验证是否摇头"><a href="#8-张嘴判断完毕，验证是否摇头" class="headerlink" title="8. 张嘴判断完毕，验证是否摇头"></a>8. 张嘴判断完毕，验证是否摇头</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">if ([key isEqualToString:@&quot;mouth_middle&quot;] &amp;&amp; isJudgeMouth == YES) &#123;</span><br><span class="line"></span><br><span class="line">        if (bigNumber == 0 ) &#123;</span><br><span class="line">            firstNumber = p.x;</span><br><span class="line">            bigNumber = p.x;</span><br><span class="line">            smallNumber = p.x;</span><br><span class="line">        &#125;else if (p.x &gt; bigNumber) &#123;</span><br><span class="line">            bigNumber = p.x;</span><br><span class="line">        &#125;else if (p.x &lt; smallNumber) &#123;</span><br><span class="line">            smallNumber = p.x;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        if (bigNumber - smallNumber &gt; 60) &#123;</span><br><span class="line">            isShakeHead = YES;</span><br><span class="line">            [self delateNumber];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h4 id="9-摇头判断完毕，3秒倒计时拍照"><a href="#9-摇头判断完毕，3秒倒计时拍照" class="headerlink" title="9. 摇头判断完毕，3秒倒计时拍照"></a>9. 摇头判断完毕，3秒倒计时拍照</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">if(timeCount &gt;= 1)</span><br><span class="line">    &#123;</span><br><span class="line">        self.textLabel.text = [NSString  stringWithFormat:@&quot;%ld s后拍照&quot;,(long)timeCount];</span><br><span class="line">    &#125;</span><br><span class="line">    else</span><br><span class="line">    &#123;</span><br><span class="line">        [theTimer invalidate];</span><br><span class="line">        theTimer=nil;</span><br><span class="line"></span><br><span class="line">        [self didClickTakePhoto];</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h4 id="10-拍照完毕，选择重拍或者上传图片"><a href="#10-拍照完毕，选择重拍或者上传图片" class="headerlink" title="10. 拍照完毕，选择重拍或者上传图片"></a>10. 拍照完毕，选择重拍或者上传图片</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">-(void)didClickPhotoAgain</span><br><span class="line">&#123;</span><br><span class="line">    [self delateNumber];</span><br><span class="line"></span><br><span class="line">    [self.previewLayer.session startRunning];</span><br><span class="line">    self.textLabel.text = @&quot;请调整位置&quot;;</span><br><span class="line"></span><br><span class="line">    [backView removeFromSuperview];</span><br><span class="line"></span><br><span class="line">    isJudgeMouth = NO;</span><br><span class="line">    isShakeHead = NO;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="11-选择重拍重复5-9步骤，选择上传将图片数据回调"><a href="#11-选择重拍重复5-9步骤，选择上传将图片数据回调" class="headerlink" title="11. 选择重拍重复5-9步骤，选择上传将图片数据回调"></a>11. 选择重拍重复5-9步骤，选择上传将图片数据回调</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-(void)didClickUpPhoto</span><br><span class="line">&#123;</span><br><span class="line">    //上传照片成功</span><br><span class="line">    [self.faceDelegate sendFaceImage:imageView.image];</span><br><span class="line">    [self.navigationController popViewControllerAnimated:YES];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="12-数据clean"><a href="#12-数据clean" class="headerlink" title="12. 数据clean"></a>12. 数据clean</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">-(void)delateNumber</span><br><span class="line">&#123;</span><br><span class="line">    number = 0;</span><br><span class="line">    takePhotoNumber = 0;</span><br><span class="line"></span><br><span class="line">    mouthWidthF = 0;</span><br><span class="line">    mouthHeightF = 0;</span><br><span class="line">    mouthWidth = 0;</span><br><span class="line">    mouthHeight = 0;</span><br><span class="line"></span><br><span class="line">    smallNumber = 0;</span><br><span class="line">    bigNumber = 0;</span><br><span class="line">    firstNumber = 0;</span><br><span class="line"></span><br><span class="line">    imgView.animationImages = nil;</span><br><span class="line">    imgView.image = [UIImage imageNamed:@&quot;shakeHead0&quot;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="四：讯飞SDK下载及配置"><a href="#四：讯飞SDK下载及配置" class="headerlink" title="四：讯飞SDK下载及配置"></a>四：讯飞SDK下载及配置</h2><h4 id="1-SDK下载"><a href="#1-SDK下载" class="headerlink" title="1. SDK下载"></a>1. SDK下载</h4><p>因为项目中使用到讯飞人脸识别SDK，需要去<a href="http://console.xfyun.cn/app/edit?appId=NWFhNjI3OTM%3D&amp;appName=RkJZRmFjZVJlY29nbml0aW9uX2lPUw%3D%3D" target="_blank" rel="noopener">讯飞开放平台</a>创建应用，下载SDK。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/2829694-b10687203a879c89.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="11.png"></p>
<h4 id="2-添加系统库"><a href="#2-添加系统库" class="headerlink" title="2. 添加系统库"></a>2. 添加系统库</h4><p>将开发工具包中lib目录下的iflyMSC.framework添加到工程中。同时请将Demo中依赖的其他库也添加到工程中。 按下图示例添加 SDK 所需要的 iOS系统库：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/2829694-93809e5d166a1633.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="88.png"></p>
<h4 id="3-设置Bitcode"><a href="#3-设置Bitcode" class="headerlink" title="3. 设置Bitcode"></a>3. 设置Bitcode</h4><p>在Targets - Build Settings 中搜索Bitcode 即可，找到相应选项，设置为NO，如下图：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/2829694-3414999985ccd080.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="333.jpg"></p>
<h4 id="4-用户隐私权限配置"><a href="#4-用户隐私权限配置" class="headerlink" title="4. 用户隐私权限配置"></a>4. 用户隐私权限配置</h4><p>在Info.plist 中增加下图设置：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/2829694-19d0d89539d05cbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="444.png"></p>
<h2 id="五：项目实际使用"><a href="#五：项目实际使用" class="headerlink" title="五：项目实际使用"></a>五：项目实际使用</h2><h4 id="1-下载demo"><a href="#1-下载demo" class="headerlink" title="1. 下载demo"></a>1. 下载demo</h4><p>下载demo，将demo中FBYFaceData文件夹引入项目中。</p>
<h4 id="2-在项目中引入FBYFaceRecognitionViewController"><a href="#2-在项目中引入FBYFaceRecognitionViewController" class="headerlink" title="2. 在项目中引入FBYFaceRecognitionViewController"></a>2. 在项目中引入FBYFaceRecognitionViewController</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">#import &quot;FBYFaceRecognitionViewController.h&quot;</span><br></pre></td></tr></table></figure>
<h4 id="3-在项目识别按钮的点击事件中添加代码"><a href="#3-在项目识别按钮的点击事件中添加代码" class="headerlink" title="3. 在项目识别按钮的点击事件中添加代码"></a>3. 在项目识别按钮的点击事件中添加代码</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-(void)pushToFaceStreamDetectorVC</span><br><span class="line">&#123;</span><br><span class="line">    FBYFaceRecognitionViewController *faceVC = [[FBYFaceRecognitionViewController alloc]init];</span><br><span class="line">    faceVC.faceDelegate = self;</span><br><span class="line">    [self.navigationController pushViewController:faceVC animated:YES];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="4-图片回调函数"><a href="#4-图片回调函数" class="headerlink" title="4. 图片回调函数"></a>4. 图片回调函数</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">-(void)sendFaceImage:(UIImage *)faceImage</span><br><span class="line">&#123;</span><br><span class="line">    NSLog(@&quot;图片上传成功&quot;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)sendFaceImageError &#123;</span><br><span class="line">    NSLog(@&quot;图片上传失败&quot;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="本篇文章demo源码："><a href="#本篇文章demo源码：" class="headerlink" title="本篇文章demo源码："></a>本篇文章demo源码：</h2><p><a href="https://github.com/fanbaoying/FBYFaceRecognitionDemo_iOS" target="_blank" rel="noopener">demo源码</a></p>
<h2 id="公众号：网罗开发"><a href="#公众号：网罗开发" class="headerlink" title="公众号：网罗开发"></a>公众号：网罗开发</h2><p><img src="http://upload-images.jianshu.io/upload_images/2829694-48307b4d71bc5800.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300" alt=""></p>

      
    </div>
    
    
    
    

    
      <div>
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      </div>
    


    
      <div>
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/人脸识别-活体检测-张嘴摇头识别/">人脸识别 -- 活体检测(张嘴摇头识别)</a></p>
  <p><span>文章作者:</span><a href="/" title="访问 Swift社区 的个人博客">Swift社区</a></p>
  <p><span>发布时间:</span>2018年03月19日 - 09:03</p>
  <p><span>最后更新:</span>2018年03月19日 - 09:03</p>
  <p><span>原始链接:</span><a href="/人脸识别-活体检测-张嘴摇头识别/" title="人脸识别 -- 活体检测(张嘴摇头识别)">https://fanbaoying.github.io/人脸识别-活体检测-张嘴摇头识别/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://fanbaoying.github.io/人脸识别-活体检测-张嘴摇头识别/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
      $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
        });
    });  
</script>

      </div>
    


    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat.png" alt="Swift社区 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="Swift社区 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/iOS/" rel="tag"><i class="fa fa-tag"></i> iOS</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/iOS-实现点击图片放大/" rel="next" title="iOS 实现点击图片放大">
                <i class="fa fa-chevron-left"></i> iOS 实现点击图片放大
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/AVFoundation-封装一个好用的视频播放器/" rel="prev" title="AVFoundation | 封装一个好用的视频播放器">
                AVFoundation | 封装一个好用的视频播放器 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
<span class="jiathis_txt">分享到：</span>
<a class="jiathis_button_fav">收藏夹</a>
<a class="jiathis_button_copy">复制网址</a>
<a class="jiathis_button_email">邮件</a>
<a class="jiathis_button_weixin">微信</a>
<a class="jiathis_button_qzone">QQ空间</a>
<a class="jiathis_button_tqq">腾讯微博</a>
<a class="jiathis_button_douban">豆瓣</a>
<a class="jiathis_button_share">一键分享</a>

<a href="http://www.jiathis.com/share?uid=2140465" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a>
<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
var jiathis_config={
  data_track_clickback:true,
  summary:"",
  shortUrl:false,
  hideMore:false
}
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=" charset="utf-8"></script>
<!-- JiaThis Button END -->
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="https://avatars.githubusercontent.com/u/84354365?v=4"
                alt="Swift社区" />
            
              <p class="site-author-name" itemprop="name">Swift社区</p>
              <p class="site-description motion-element" itemprop="description">我们的使命是做一个最专业最权威的 Swift 中文社区，我们的愿景是希望更多的人学习和使用Swift。我们会分享以 Swift 实战、SwiftUI、Swift 基础为核心的技术干货，不忘初心，牢记使命。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">187</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_36478920" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>CSDN</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/5a30d987f265da430d580126" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-spinner"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/fanbaoying" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/swift-community" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>知乎</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/u/7711465033" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAxNzgzNTgwMw==&action=getalbum&album_id=2024314764775981057" target="_blank" title="公众号">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>公众号</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/SwiftCommunityRes/SwiftWeekly" title="SwiftWeekly" target="_blank">SwiftWeekly</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/SwiftCommunityRes/article-ios" title="Article-ios" target="_blank">Article-ios</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/SwiftCommunityRes/SwiftUI-Book" title="SwiftUI-Book" target="_blank">SwiftUI-Book</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一：简介"><span class="nav-number">1.</span> <span class="nav-text">一：简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二：实现思路分析"><span class="nav-number">2.</span> <span class="nav-text">二：实现思路分析</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三：实现源码分析"><span class="nav-number">3.</span> <span class="nav-text">三：实现源码分析</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-点击识别按钮，调用相机"><span class="nav-number">3.0.1.</span> <span class="nav-text">1. 点击识别按钮，调用相机</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-CameraRules类，检测相机权限"><span class="nav-number">3.0.2.</span> <span class="nav-text">2. CameraRules类，检测相机权限</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-初始化页面，创建摄像页面，创建张嘴数据和摇头数据"><span class="nav-number">3.0.3.</span> <span class="nav-text">3. 初始化页面，创建摄像页面，创建张嘴数据和摇头数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-开启识别，脸部框识别"><span class="nav-number">3.0.4.</span> <span class="nav-text">4. 开启识别，脸部框识别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-脸部部位识别，脸部识别判断是否检测到人脸"><span class="nav-number">3.0.5.</span> <span class="nav-text">5. 脸部部位识别，脸部识别判断是否检测到人脸</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-检测到人脸之后，判断位置动作提醒"><span class="nav-number">3.0.6.</span> <span class="nav-text">6. 检测到人脸之后，判断位置动作提醒</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-位置判断合适，判断是否张嘴"><span class="nav-number">3.0.7.</span> <span class="nav-text">7. 位置判断合适，判断是否张嘴</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8-张嘴判断完毕，验证是否摇头"><span class="nav-number">3.0.8.</span> <span class="nav-text">8. 张嘴判断完毕，验证是否摇头</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-摇头判断完毕，3秒倒计时拍照"><span class="nav-number">3.0.9.</span> <span class="nav-text">9. 摇头判断完毕，3秒倒计时拍照</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#10-拍照完毕，选择重拍或者上传图片"><span class="nav-number">3.0.10.</span> <span class="nav-text">10. 拍照完毕，选择重拍或者上传图片</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#11-选择重拍重复5-9步骤，选择上传将图片数据回调"><span class="nav-number">3.0.11.</span> <span class="nav-text">11. 选择重拍重复5-9步骤，选择上传将图片数据回调</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#12-数据clean"><span class="nav-number">3.0.12.</span> <span class="nav-text">12. 数据clean</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四：讯飞SDK下载及配置"><span class="nav-number">4.</span> <span class="nav-text">四：讯飞SDK下载及配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-SDK下载"><span class="nav-number">4.0.1.</span> <span class="nav-text">1. SDK下载</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-添加系统库"><span class="nav-number">4.0.2.</span> <span class="nav-text">2. 添加系统库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-设置Bitcode"><span class="nav-number">4.0.3.</span> <span class="nav-text">3. 设置Bitcode</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-用户隐私权限配置"><span class="nav-number">4.0.4.</span> <span class="nav-text">4. 用户隐私权限配置</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五：项目实际使用"><span class="nav-number">5.</span> <span class="nav-text">五：项目实际使用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-下载demo"><span class="nav-number">5.0.1.</span> <span class="nav-text">1. 下载demo</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-在项目中引入FBYFaceRecognitionViewController"><span class="nav-number">5.0.2.</span> <span class="nav-text">2. 在项目中引入FBYFaceRecognitionViewController</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-在项目识别按钮的点击事件中添加代码"><span class="nav-number">5.0.3.</span> <span class="nav-text">3. 在项目识别按钮的点击事件中添加代码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-图片回调函数"><span class="nav-number">5.0.4.</span> <span class="nav-text">4. 图片回调函数</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#本篇文章demo源码："><span class="nav-number">6.</span> <span class="nav-text">本篇文章demo源码：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#公众号：网罗开发"><span class="nav-number">7.</span> <span class="nav-text">公众号：网罗开发</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Swift社区</span>

  
</div>

<!-- 
<div class="powered-by">
  <i class="fa fa-user-md">
  </i>
  <span id="busuanzi_container_site_uv">
    已有<span id="busuanzi_value_site_uv"></span>人来访
  </span>

</div>


  <span class="post-meta-divider">|</span>


<div class="powered-by">
  <i class="fa fa-eye"></i>
  <span id="busuanzi_container_site_pv">
      访问量<span id="busuanzi_value_site_pv"></span>次
  </span>
</div>



  <span class="post-meta-divider">|</span>


-->

<div class="theme-info">
  <i class="fa fa-pencil"></i>
  <span class="post-count">博客全站共361.6k字</span>
</div>


<!-- 
  <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>



-->

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
